#include "stdafx.h"
#include "Task.h"

double Task::getK( double x )
{
	double k;
	switch (type)
	{
	case TaskTypeTesting: 
		if (x < gapPoint) k = exp(-gapPoint);
		else k = gapPoint*gapPoint + 1;
		break;
	case TaskTypeMyTask: 
		if (x < gapPoint) k = exp((-1) * x);
		else k = x*x + 1;
		break;
	case TaskTypeTesting2:
		k = 1;
		break;
	}
	return k;
}

double Task::getQ( double x )
{
	double q;
	switch (type)
	{
	case TaskTypeTesting: 
		if (x < gapPoint) q = gapPoint*gapPoint*gapPoint + 1;
		else q = gapPoint;
		break;
	case TaskTypeMyTask: 
		if (x < gapPoint) q = x*x*x + 1;
		else q = x;
		break;
	case TaskTypeTesting2:
		q = 1;
		break;
	}
	return q;
}


double Task::getF( double x )
{
	double f;
	switch (type)
	{
	case TaskTypeTesting: 
		if (x < gapPoint) f = gapPoint*gapPoint - 1;
		else f = 1;
		break;
	case TaskTypeMyTask: 
		if (x < gapPoint) f = x*x - 1;
		else f = 1;
		break;
	case TaskTypeTesting2:
		f = x*x - 2;
		break;
	}
	return f;
}

double Task::getFunction( double x )
{
	double f = 0.0;
	switch (type)
	{
	case TaskTypeTesting:
		if (x < gapPoint) f = 2.2640997148514*exp(-1.4574381159607928719*x) + 0.294973299951*exp(1.4574381159607928719*x) - 0.55907301480239405434;
		else f = -0.2623021124785*exp(-0.65803700647624623041*x) - 0.3087635514505*exp(0.65803700647624623041*x) + 1.7320594040815772935;
		break;
	case TaskTypeTesting2:
		f = x*x;
		break;
	}
	return f;
}

double Task::getC( double x_start, double x_end )
{
	double C;
	double h_ = 1 / (x_end - x_start);
	switch (type)
	{
	case TaskTypeTesting:
		if (x_end < gapPoint) C = gapPoint*gapPoint*gapPoint + 1;
		else if (x_start > gapPoint) C = gapPoint;
		else C = h_ * ((gapPoint*gapPoint*gapPoint + 1)*(gapPoint - x_start) + gapPoint*(x_end - gapPoint));
		break;
	case TaskTypeTesting2:
		C = 1;
		break;
	case TaskTypeMyTask:
		if (x_end <= gapPoint) C = h_*((x_end*x_end*x_end*x_end - x_start*x_start*x_start*x_start) / 4 + x_end - x_start);
		else if (x_start >= gapPoint) C = h_ * (x_end*x_end - x_start*x_start) / 2;
		else C = h_ * ((gapPoint*gapPoint*gapPoint*gapPoint - x_start*x_start*x_start*x_start) / 4 + gapPoint - x_start + (x_end*x_end - gapPoint*gapPoint) / 2);
		break;
	}
	return C;
}

double Task::getAB( double x_start, double x_end )
{
	double A;
	double h_ = 1 / (x_end - x_start);
	switch (type)
	{
	case TaskTypeTesting:
		if (x_end < gapPoint) A = (h_*h_) / (exp(gapPoint));
		else if (x_start > gapPoint) A = (1 + gapPoint*gapPoint) * (h_*h_);
		else A = h_ / (exp(gapPoint)*(gapPoint - x_start) + (x_end - gapPoint) / (1 + gapPoint*gapPoint));
		break;
	case TaskTypeTesting2:
		A = h_*h_;
		break;
	case TaskTypeMyTask:
		if (x_end < gapPoint) A = h_ / (exp(x_end) - exp(x_start));
		else if (x_start > gapPoint) A = h_ / (atan(x_end) - atan(x_start));
		else A = h_ / (exp(gapPoint) - exp(x_start) + atan(x_end) - atan(gapPoint));
		break;
	}
	return A;
}

double Task::getPhi( double x_start, double x_end )
{
	double Phi;
	double h_ = 1 / (x_end - x_start);
	switch (type)
	{
	case TaskTypeTesting:
		if (x_end < gapPoint) Phi = gapPoint*gapPoint - 1;
		else if (x_start > gapPoint) Phi = 1;
		else Phi = h_*((gapPoint*gapPoint - 1)*(gapPoint - x_start) + x_end - gapPoint);
		break;
	case TaskTypeTesting2:
		//Phi = h_*((x_end*x_end*x_end - x_start*x_start*x_start)/3 + 2*(x_start - x_end));
		Phi = (x_end+x_start)*(x_end+x_start) / 4 - 2;
		break;
	case TaskTypeMyTask:
		if (x_end < gapPoint) Phi = h_ *((x_end*x_end*x_end - x_start*x_start*x_start)/3 + x_start - x_end);
		else if (x_start > gapPoint) Phi = 1;
		else Phi = h_*((gapPoint*gapPoint*gapPoint - x_start*x_start*x_start)/3 + x_start + x_end - 2*gapPoint);
		break;
	}
	return Phi;
}
